/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package manager;

import java.util.HashMap;
import java.util.Map;
import model.Packet;
import model.Path;
import model.Queue;

/**
 *
 * @author wpc
 */
public class QueueManager {

    private Map<Integer, Queue> map;

    private PathManager pm;

    public QueueManager(PathManager pm) {
        this.pm = pm;
        map = new HashMap<Integer, Queue>();
    }

    public void addQueue(Queue queue){
        map.put(queue.getId(), queue);
    }

    /**
     * Finish or loss will return true
     * @param packet
     * @return
     */
    public boolean isLoss(Packet packet){
        Queue queue = map.get(pm.queueId(packet));
        return queue.isLoss(packet);
    }

    public boolean departure(Packet packet){
        Queue queue = map.get(pm.queueId(packet));
        queue.leave(packet);
        queue = map.get(pm.queueId(packet));
        return queue.isFinish(packet);
    }
}
